﻿function helpDialog(contextPath){
	var self=this;
	this._title="帮助窗口标题";
	this._message="这是用来帮助客户理解报表的窗口~~~~~";
	this._closeImg=contextPath+"/images/help_img/help_close.gif";
	this._display=false;
	this._bgDiv=generateBg();
	this._dgDiv=generateDialog();
	
	
	$(window).resize(function(){
		auto();
	})
	
	//生产一个dialog
	function generateDialog(){
		var mainDiv=document.createElement("DIV");
		var contentDiv=document.createElement("DIV");
		mainDiv.appendChild(contentDiv);
		
		$(mainDiv).css({
			//opacity:"0.5",
			width:"620px",
			height:"420px",
			//background:"orange",
			position:"absolute",
			"z-index":"10001",
			"text-align":"center"
		});
		
		$(contentDiv).append(
			"<div class='opwindow_title' style='height:33px; background:#fb8615; width:100%; padding-bottom:3px; line-height:30px; color:#fff;'>"+
				"<ul style='background:#0c4f78; height:30px; width:100%;'>"+
				"<li style='padding-left:12px; font-size:16px; font-weight:bold; line-height:30px; float:left;'>"+self._title+"</li>"+
				"<li class='opwindow_close' >"+
				"<a href='javascript:void(0)' id='close' style='float:right; width:30px; height:30px; padding-right:10px; background:url("+self._closeImg+") no-repeat; cursor:pointer;'></a>"+
				"</li>"+
				"</ul>"+
			"</div>"+
			"<div style='padding:10px 20px; color:#666; line-height:30px; font-size:14px;text-align:left'>"+
			self._message+
			"</div>"
		);
		
		
		$(contentDiv).css({
			opacity:"1.0",
			position:"absolute",
			width:"600px",
			height:"400px",
			background:"white",
			//"margin-left":"10px",
			//"margin-top":"10px",
			top:"10px",
			left:"10px"
		});
		return  mainDiv;
	}
	//生产一个背景div
	function generateBg(){
		var bgDiv=document.createElement("DIV");
		$(bgDiv).css({
			opacity:"0.9",
			position:"absolute",
			background:"#363636",
			"z-index":"10000"
		});
		return bgDiv;
	}
	
	function auto(){
		if(self._display!=true){
			return;
		}
		
		
		document.body.style.overflow="hidden";//
		document.documentElement.style.overflow='hidden';
		var bg_top=document.body.scrollTop||document.documentElement.scrollTop;
		var bg_h=
			$(window).height();
		var bg_w=document.body.offsetWidth;
		var bg_left=document.body.scrollLeft;
		$(self._bgDiv).css({
			width:bg_w+"px",
			height:bg_h+"px",
			//width:"100%",
			//height:"100%",
			top:bg_top+"px",
			left:bg_left+"px"
			//top:"0px",
			//left:"0px"
		});
		
		
		var dg_top=(bg_h-$(self._dgDiv).height())/2+bg_top;
		var dg_left=(bg_w-$(self._dgDiv).width())/2+bg_left;
		$(self._dgDiv).css({
			top:dg_top+"px",
			left:dg_left+"px"
		});
		
	}
	
	
	/*
	*公共方法
	*/
	this.show=function(){
		this._display=true;
		auto();
		document.body.appendChild(this._bgDiv);
		document.body.appendChild(this._dgDiv);
		var self=this;
		
		if(!self._closeEvent){
			$("a#close").click(function(){
				self._closeEvent=true;
				self.hide();
			});
		}
		
		
	}
	
	this.hide=function(){
		this._display=false;
		document.body.removeChild(this._dgDiv);
		document.body.removeChild(this._bgDiv);
		document.body.style.overflow="auto";//
		document.documentElement.style.overflow='auto';
	}
}